
public class AQByteUtil {

	public AQByteUtil() {
	}
	
	static final String byteBufferToHexString( byte[] buffer, int maxNbOfBytes) {
		if( buffer == null) {
			return null;
		}
		
		int offset = 0;
		boolean isFirst = true;
		StringBuffer sb = new StringBuffer();
		
		while( offset < buffer.length && offset < maxNbOfBytes) {
			if( !isFirst) {
				sb.append( ' ');
			} else {
				isFirst = false;
			}
			
			String hexrep = Integer.toHexString( ( int)buffer[offset]&0xFF);
			
			if( hexrep.length() == 1) {
				hexrep = "0" + hexrep;
			}
			
			sb.append( hexrep);
			offset++;
		}
		String ret = sb.toString();
		
		return ret;
	}
	
	static final String byteBufferToHexString( byte[] buffer) {
		if( buffer == null) {
			return null;
		}
		
		int offset = 0;
		boolean isFirst = true;
		StringBuffer sb = new StringBuffer();
		
		while( offset < buffer.length) {
			if( !isFirst) {
				sb.append( ' ');
			} else {
				isFirst = false;
			}
			
			String hexrep = Integer.toHexString( ( int)buffer[offset]&0xFF);
			
			if( hexrep.length() == 1) {
				hexrep = "0" + hexrep;
			}
			
			sb.append( hexrep);
			offset++;
		}
		String ret = sb.toString();
		
		return ret;
	}

}
